package com.finiac.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.finiac.dao.SalesDAO;
import com.finiac.model.Sales;

public class AccountController extends MultiActionController {

	SalesDAO salesDAO;
	
	public void setSalesDAO(SalesDAO salesDAO) {
		this.salesDAO = salesDAO;
	} 

	public ModelAndView dailyAccountSummary(HttpServletRequest request, HttpServletResponse response)throws Exception
	{
		String date= request.getParameter("date");
		if(date=="")
			date="00/00/0000";
		ModelMap modelMap = new ModelMap();
		modelMap.addAttribute("items", salesDAO.selectByDate(date));
		modelMap.addAttribute("bill", new Sales());
		return new ModelAndView("dailyAccountSummary",modelMap);
	}
	public ModelAndView monthlyAccountSummary(HttpServletRequest request, HttpServletResponse response)throws Exception
	{
		String month= request.getParameter("month");
		String year= request.getParameter("year");
		if(month=="" || year =="")
		{
			month="00";
			year="00";
		}
		ModelMap modelMap = new ModelMap();
		modelMap.addAttribute("items", salesDAO.selectByMonth(month,year));
		modelMap.addAttribute("bill", new Sales());
		return new ModelAndView("monthlyAccountSummary",modelMap);
	}
}
